package io.renren.modules.yst.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.yst.dao.CheckRecordVoDao;
import io.renren.modules.yst.entity.WorkerCardEntity;
import io.renren.modules.yst.vo.CheckRecordVo;
import io.renren.modules.yst.vo.RecordByCarVo;
import io.renren.modules.yst.vo.RecordByDateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.yst.dao.WorkerCardRecordDao;
import io.renren.modules.yst.entity.WorkerCardRecordEntity;
import io.renren.modules.yst.service.WorkerCardRecordService;


@Service("workerCardRecordService")
public class WorkerCardRecordServiceImpl extends ServiceImpl<WorkerCardRecordDao, WorkerCardRecordEntity> implements WorkerCardRecordService {

    @Autowired
    private CheckRecordVoDao checkRecordVoDao;

    @Autowired
    private WorkerCardRecordDao workerCardRecordDao;

    @Override
    public PageUtils  queryPage(Page<CheckRecordVo> page, QueryWrapper<CheckRecordVo> queryWrapper) {

        IPage<CheckRecordVo> result=checkRecordVoDao.findByPage(page,queryWrapper.orderByDesc("create_time"));

        return new PageUtils(result);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        IPage<WorkerCardRecordEntity> page = this.page(
                new Query<WorkerCardRecordEntity>().getPage(params),
                new QueryWrapper<WorkerCardRecordEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params, String orderby, boolean isAsc) {
        IPage<WorkerCardRecordEntity> page = this.page(
                new Query<WorkerCardRecordEntity>().getPage(params,orderby,false),
                new QueryWrapper<WorkerCardRecordEntity>()
        );

        return new PageUtils(page);
    }
    @Override
    public void create(WorkerCardEntity workerCard, SysUserEntity user) {

        WorkerCardRecordEntity workerCardRecord=new WorkerCardRecordEntity();
        workerCardRecord.setCardId(workerCard.getCardId());
        workerCardRecord.setCreateTime(new Date());
        workerCardRecord.setManagerId(user.getUserId());
        this.save(workerCardRecord);


    }

    @Override
    public List<RecordByDateVo> queryCountByDate(String startDate, String endDate) {



        return this.queryCountByDate("%Y-%c-%d",startDate,endDate);
    }
    @Override
    public List<RecordByCarVo> queryCountByCarNumber(String startDate, String endDate) {



        return workerCardRecordDao.queryCountByCarNumber(startDate,endDate);
    }

    @Override
    public List<RecordByDateVo> queryCountByDate(String format ,String startDate, String endDate) {



        return workerCardRecordDao.queryCountByDate(startDate,endDate,format);
    }
    public PageUtils queryPageForManager(Page<CheckRecordVo> page, QueryWrapper<CheckRecordVo> queryWrapper) {
        IPage<CheckRecordVo> result=checkRecordVoDao.findByPageForManager(page,queryWrapper.orderByDesc("create_time"));

        return new PageUtils(result);
    }

}